/**
 * 显示消息提示框
 * @param content 提示的标题
 */
export function toast(content) {
	uni.showToast({
		icon: 'none',
		title: content
	})
}
export function getFormatDate(cellValue) {
	if (cellValue == null || cellValue == "") return "";
	var date = new Date(cellValue)
	var year = date.getFullYear()
	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
	var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
	var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
	var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
	return year + '-' + month + '-' + day + ' '
}
export function getFormatTime(cellValue) {
	if (cellValue == null || cellValue == "") return "";
	var date = new Date(cellValue)
	var year = date.getFullYear()
	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
	var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
	var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
	var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
	return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}
/**
 * 显示模态弹窗
 * @param content 提示的标题
 */
export function showConfirm(content) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: '提示',
			content: content,
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				resolve(res)
			}
		})
	})
}

/**
 * 参数处理
 * @param params 参数
 */
export function tansParams(params) {
	let result = ''
	for (const propName of Object.keys(params)) {
		const value = params[propName]
		var part = encodeURIComponent(propName) + "="
		if (value !== null && value !== "" && typeof(value) !== "undefined") {
			if (typeof value === 'object') {
				for (const key of Object.keys(value)) {
					if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
						let params = propName + '[' + key + ']'
						var subPart = encodeURIComponent(params) + "="
						result += subPart + encodeURIComponent(value[key]) + "&"
					}
				}
			} else {
				result += part + encodeURIComponent(value) + "&"
			}
		}
	}
	return result
}
/**
 * 文件预览
 * @param params 参数
 */
export function previewFile(url) {
	uni.showLoading({
		mask: true
	})
	let vm = this
	uni.downloadFile({
		url: url,
		success: function(res) {
			var filePath = res.tempFilePath;
			uni.openDocument({
				filePath: filePath,
				showMenu: true,
				success: function(res) {
					console.log('预览成功');
				},
				fail(e) {
					console.log(e)
					vm.$toast('预览失败')
				}
			});
		},
		fail(e) {
			console.log(e)
			vm.$toast('预览失败')
		},
		complete(e) {
			uni.hideLoading()
		}
	});
}
// 检测方法code
export function getMethodCode(code) {
	let checkFlag = 0
	if (code == 2012 || code == 2013 || code == 2014 || code == 2022) {
		checkFlag = 0
	}
	/** 桩的完整性;2033水泥掺量(%)*/ 
	if (code == 2023 || code == 2031 || code == 2032 || code == 2033) {
		checkFlag = 1
	}
	/** 地基与复合地基*/
	if (code == 2011) {
		checkFlag = 2
	}
	/** 锚杆*/
	if (code == 2015) {
		checkFlag = 3
	}
	/** 成孔质量*/
	if (code == 2035) {
		checkFlag = 4
	}
	return  checkFlag
}